package beans.xml;

import java.io.File;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

public class DOM4JTest
{

	public static void main(String[] args) throws Exception
	{
		SAXReader reader = new SAXReader();

		Document doc = reader.read(new File("d:/1.xml"));
		Element root = doc.getRootElement();// 根节点;
		@SuppressWarnings("unchecked")
		List<Element> list = root.elements();
		// List<Node> nameElement = (List<Node>) root.selectNodes("//student/name[@id='1']");
		for (Node level2 : list)
		{// 遍历二级节点
			level2.getParent().add(level2);

			System.out.println("DOM4JTest.main()" + ((Element) level2.clone()).asXML().toString());

			// System.out.println("DOM4JTest.main()" + doc.asXML().toString());
		}
	}

}

// <?xml version="1.0" encoding="GB2312"?>
//
// <?xml-stylesheet type="text/xsl" href="students.xsl"?>
//
// <students>
// <student sn="01">
// <name>张三</name>
// <age>18</age>
// </student>
//
// <student sn="02">
// <name>李四</name>
// <age>20</age>
// </student>
// </students>
